package com.bigflexlib.core.comparison.simple
{
	
	import com.bigflexlib.core.comparison.result.ComparisonResult;
	import com.bigflexlib.core.comparison.result.ComparisonResults;
	
	
	/**
	 * 
	 * @author aldo.bucchi@gmail.com
	 * 
	 */	
	public class SimpleComparableComparator implements ISimpleComparator
	{

		/**
		 * 
		 * @param value1
		 * @param value2
		 * @return 
		 * 
		 */
		public function compare( value1:*, value2:* ):ComparisonResult
		{
			
			// cheapest comparison first
			if ( value1 === value2 ) return ComparisonResults.EQUAL;
			
			if ( ! value1 is ISimpleComparable ) return ComparisonResults.DIFFERENT;
			if ( ! value2 is ISimpleComparable ) return ComparisonResults.DIFFERENT;
			
			return ( value1 as ISimpleComparable ).compare( value2 );			

		}


		
		/////////////////////////////////////////////////////////////////////
		//////////////////////////// singleton //////////////////////////////
		/////////////////////////////////////////////////////////////////////
		

		
		private static var _instance:SimpleComparableComparator;
		public static function get i( ):SimpleComparableComparator
		{
			if ( !_instance )
				_instance = new SimpleComparableComparator( );
			return _instance;		
		}	
		
		
	}

}